#ifndef __PFEXPORTER_H_INCLUDED__
#define __PFEXPORTER_H_INCLUDED__

#include <irrlicht.h>
#include <vector>

class CAdvancedMeshCollision;

struct RoomMapInfo
{	
	irr::scene::ISceneNode* Node;
	irr::core::stringc FileName;
	bool NeedExport;

	irr::core::aabbox3df AABBox;
	CAdvancedMeshCollision** collision_array;
	irr::s32 collision_num;

	RoomMapInfo():collision_array(0),collision_num(0)
	{
	}

	~RoomMapInfo();

	void PreCompute(irr::scene::ISceneNode* RoomRootNode);
};


class PFExporter
{
public:
	static void SetTileSize(int ts)
	{
		s_TileSize = ts;
	}

	static void SetTileSizeZ(int ts)
	{
		s_TileSizeZ = ts;
	}
	
	static void SetMinValue(int min)
	{
		s_MinValue = min;
	}

	static void SetMaxValue(int max)
	{
		s_MaxValue = max;
	}

	static void SetOffset(int offset)
	{
		s_Offset = offset;
	}

	static int GetTileSize()
	{
		return s_TileSize;
	}

	static int GetTileSizeZ()
	{
		return s_TileSizeZ;
	}

	static int GetMinValue()
	{
		return s_MinValue;
	}

	static int GetMaxValue()
	{
		return s_MaxValue;
	}

	static int GetOffset()
	{
		return s_Offset;
	}

	static void SetRGBScale(float r, float g, float b)
	{
		s_scaleR = r;
		s_scaleG = g;
		s_scaleB = b;
	}

	static void GetRGBScale(float& r, float& g, float& b)
	{
		r = s_scaleR;
		g = s_scaleG;
		b = s_scaleB;
	}

	static void ClearRoomMaps()
	{
		s_roomMaps.clear();
	}

	static void FreeMemory()
	{
		std::vector<RoomMapInfo*>::iterator iter = s_roomMaps.begin();
		for(;iter!=s_roomMaps.end();++iter)
		{
			delete *iter;
		}
		s_roomMaps.clear();
	}

	static void AddRoomMap(irr::scene::ISceneNode* roomRootNode, const irr::core::stringc& fileName)
	{
		RoomMapInfo* info = new RoomMapInfo();		
		info->FileName = fileName;
		info->PreCompute(roomRootNode);
		s_roomMaps.push_back(info);
	}

	static std::vector<RoomMapInfo*>& GetRoomMaps()
	{
		return s_roomMaps;
	}

	static void Export(irr::scene::ISceneManager* smgr, int i, int tileSize, int tileSizeZ)
	{
		if(i<0 || i>=s_roomMaps.size())
			return;
				
		RoomMapInfo& info = *s_roomMaps[i];
		ExportIlluminationMap(smgr, info, tileSize, tileSizeZ);		
	}

private:
	static void	ExportIlluminationMap(irr::scene::ISceneManager* smgr, RoomMapInfo& info, int tileSize, int tileSizeZ);

	static std::vector<RoomMapInfo*> s_roomMaps;

	static int s_TileSize, s_TileSizeZ;

	static int s_MinValue, s_MaxValue, s_Offset;

	static float s_scaleR, s_scaleG, s_scaleB;
};
 
#endif
